<?php
/**
 * 前台首页控制器
 */
class IndexController extends CommonController{
    public function index(){
        // 共用导航分类
    	$this->category();
    	$c_model = K('Category'); 
    	// 女装子分类
    	$this->assign("c_data1",$c_model->get_c_data(11,8));
        // 女装左侧3件随机商品
        $ladies1 = M('goods')->where('category_cid=13')->order('rand()')->limit(3)->getField('gid,gname,pic,goods_price,type_tid');
        foreach ($ladies1 as $k => $v) {
            $ladies1[$k]['pic'] = str_replace('.', '_s.', $v['pic']);
            $ladies1[$k]['gname'] = mb_substr($v['gname'],0,10,'utf-8');
        }
        $this->assign("ladies1",$ladies1);
        // 男装子分类
    	$this->assign("c_data2",$c_model->get_c_data(34,8));

        //男装4件随机商品
        $men_wear1 = M('goods')->where('category_cid=39')->order('rand()')->limit(4)->getField('gid,gname,pic,goods_price,type_tid');
        foreach ($men_wear1 as $k => $v) {
            $men_wear1[$k]['pic'] = str_replace('.', '_b.', $v['pic']);
            $men_wear1[$k]['gname'] = mb_substr($v['gname'],0,10,'utf-8');
        }
        $this->assign("men_wear1",$men_wear1);

        //男装休闲裤2件随机商品
        $men_wear2 = M('goods')->where('category_cid=45')->order('rand()')->limit(2)->getField('gid,gname,pic,goods_price,type_tid');
        foreach ($men_wear2 as $k => $v) {
            $men_wear2[$k]['pic'] = str_replace('.', '_s.', $v['pic']);
            $men_wear2[$k]['gname'] = mb_substr($v['gname'],0,10,'utf-8');
        }
        // p($men_wear2);
        $this->assign("men_wear2",$men_wear2);
        //男装牛仔裤2件随机商品
        $men_wear3 = M('goods')->where('category_cid=46')->order('rand()')->limit(2)->getField('gid,gname,pic,goods_price,type_tid');
        foreach ($men_wear3 as $k => $v) {
            $men_wear3[$k]['pic'] = str_replace('.', '_s.', $v['pic']);
            $men_wear3[$k]['gname'] = mb_substr($v['gname'],0,10,'utf-8');
        }
        // p($men_wear2);
        $this->assign("men_wear3",$men_wear3);

        // ====内衣子分类
    	$this->assign("c_data3",$c_model->get_c_data(54,6));
        // 内衣右侧3件随机商品
        $ladies2 = M('goods')->where('category_cid=62')->order('rand()')->limit(3)->getField('gid,gname,pic,goods_price,type_tid');
        foreach ($ladies2 as $k => $v) {
            $ladies2[$k]['pic'] = str_replace('.', '_s.', $v['pic']);
            $ladies2[$k]['gname'] = mb_substr($v['gname'],0,10,'utf-8');
        }
        $this->assign("ladies2",$ladies2);


    	


        $this->display();
    }
 
  
}
